/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This file is part of JMail                                              *
 * Copyright (C) 2002-2003 Yvan Norsa <norsay@wanadoo.fr>                  *
 *                                                                         *
 * JMail is free software; you can redistribute it and/or modify           *
 * it under the terms of the GNU General Public License as published by    *
 * the Free Software Foundation; either version 2 of the License, or       *
 * any later version.                                                      *
 *                                                                         *
 * JMail is distributed in the hope that it will be useful,                *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 * GNU General Public License for more details.                            *
 *                                                                         *
 * You should have received a copy of the GNU General Public License along *
 * with JMail; if not, write to the Free Software Foundation, Inc.,        *
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                 *
 *                                                                         *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;

/** Representation of a filter */
final class Filter
{
    /** Name of the filter */
    private String name;

    /** Condition on which check the trigger (from, subject, dest) */
    private String condition;

    /** Trigger to operate */
    private String trigger;

    /** Action to execute (move, copy, delete) */
    private String action;

    /** Target directory if needed */
    private String target;

    /** Boolean saying wether the filter is currently used or not */
    private boolean activated;

    /** Constructor
     *  @param name name of the filter
     *  @param condition condition for the trigger to be checked
     *  @param trigger trigger to check
     *  @param action action to execute
     *  @param target target directory
     *  @param activated true if the filter is used
     */
    protected Filter(String name, String condition, String trigger, String action, String target, boolean activated)
    {
	this.name= name;
	this.condition = condition;
	this.trigger = trigger;
	this.action = action;
	this.target = target;
	this.activated = activated;
    }

    /** Returns the name of the filter
     *  @return filter name
     */
    protected final String getName()
    {
	return(name);
    }

    /** Returns the condition
     *  @return condition
     */
    protected final String getCondition()
    {
	return(condition);
    }

    /** Returns the trigger
     *  @return trigger
     */
    protected final String getTrigger()
    {
	return(trigger);
    }

    /** Returns the action
     *  @return action
     */
    protected final String getAction()
    {
	return(action);
    }

    /** Returns the target directory
     *  @return target directory
     */
    protected final String getTarget()
    {
	return(target);
    }

    /** Activates a filter or not
     *  @param activated true if the filter must be applied
     */
    protected final void setActivated(boolean activated)
    {
	this.activated = activated;
    }

    /** Tells wether the filter is used or not
     *  @return boolean : true if the filter is used
     */
    protected final boolean isActivated()
    {
	return(activated);
    }

       /** Writes a filter to an output stream (the user profile)
     *  @param out the output stream to be writed to
     */
    protected final void write(PrintWriter out)
    {
	    out.println("<Filter name=\"" + name + "\" condition=\"" + condition + "\" trigger=\"" + trigger+ "\" action=\"" + action + "\" target=\"" + target + "\" activated=\"" + activated + "\"/>");
    }
}
